<?php

/**
 * This is the model class for table "{{user_group}}".
 *
 * The followings are the available columns in table '{{user_group}}':
 * @property string $id
 * @property string $name
 */
class UserGroup extends CActiveRecord
{
	const ROOT_ADMIN 	= 1;
    const ADMIN 		= 2;
    const SUPER_MOD 	= 3;
    const MOD 			= 4;
    const VIP_MEMBER 	= 5;
    const MEMBER 		= 6;
    const VALIDATING	= 7;
    const BANNED 		= 8;

	public static function model($className=__CLASS__) {return parent::model($className);}
	public function tableName() {return '{{user_group}}';}
	public function rules()
	{
		// Define only rules for those attributes that will receive user inputs.
		return array(
			array('name', 'required'),
			array('name', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, name', 'safe', 'on'=>'search'),
		);
	}

	public function relations()
	{
		return array(
			'users'=>array(self::HAS_MANY,'User','group_id'),
		);
	}
	
	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' 	=> Yii::t('usergroup', 'ID'),
			'name' 	=> Yii::t('usergroup', 'Nhóm'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,false);
		$criteria->compare('name',$this->name,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
			'sort'=>array('defaultOrder'=>'id ASC'),
			'pagination'=>array('pageSize'=>100),
		));
	}
}